<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>搜索</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <style>
        html,
        body {
            font-size: 14px;
            height: 100%;
        }

        header {
            height: 75px;
            position: fixed;
            top: 0;
            width: 100%;
            height: 75px;
            text-align: left;
            background-color: #FBB40E;
            border-bottom: 1px solid #fff;
            z-index: 999;
        }

        header .head {
            margin-top: 38px;
            display: flex;
            justify-content: flex-start;
            align-items: center;
        }

        .head img {
            width: 1.5rem;
            height: 1.5rem;
            margin-left: 1rem;
            margin-right: 1rem;
        }

        .head .search {
            width: 70%;
            padding: 0.5rem;
            padding-left: 3rem;
            box-sizing: border-box;
            background: url(../image/icon/search.png)no-repeat center;
            background-size: 1.2rem 1.2rem;
            background-position-x: 0.7rem;
            background-color: #fff;
            border-radius: 0.5rem;
        }

        .head .searchBtn {
            margin-left: 1rem;
            font-size: 1.1rem;
            color: #fff;
        }

        main {
            padding-top: 75px;
        }

        .searchbox {
            display: block;
        }

        .searchbox .hot {
            width: 90%;
            padding-top: 1rem;
            margin: auto;
            color: #666;
        }

        .searchbox .searchHistory {
            padding: 1rem;
            display: flex;
            justify-content: flex-start;
        }

        .searchbox .searchHistory div {
            padding: 0.5rem;
            margin-right: 1rem;
            background-color: #f2f2f2;
        }

        .infolist-content li {
            padding: 0.3rem 1rem 0.5rem;
            border-bottom: 1px solid #f2f2f2;
            background-color: #fff;
        }

        .infolist-content li div {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 0.3rem;
        }

        .jobname span:nth-child(1) {
            width: 80%;
            color: #333;
            font-size: 1.1rem;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .jobcompany {
            color: #989898;
            font-size: 1rem;
        }

        .jobcompany img {
            width: 1.5rem;
            height: 1.5rem;
            margin-right: 0.5rem;
        }

        .jobaddress .length span {
            font-size: 1rem;
            color: #FFBF78;
            padding: 0.1rem;
            border: 1px solid #FFBF78;
            border-radius: 0.35rem;
            margin-right: 0.5rem;
        }

        .jobaddress .readcount {
            color: #2E7AFA;
        }

        .readcount img {
            width: 1.5rem;
            height: 1.5rem;
            margin-right: 0.3rem;
        }
    </style>
</head>

<body>
    <header>
        <div class="head">
            <img src="../image/icon/back.png" alt="" onclick="api.closeWin()">
            <input type="text" class="search" value="" placeholder="成都都在搜：实习">
            <button class="searchBtn">搜索</button>
        </div>
    </header>
    <main>
        <div class="searchbox">
            <div class="hot">热门搜索</div>
            <div class="searchHistory">
                <div id="Clerk">店员</div>
                <div id="Leaflets">派单</div>
            </div>
        </div>
        <ul class="infolist-content">

        </ul>
    </main>

</body>
<script type="text/template" id="job">
    {{~it.items:value:index}}
    <li data-id="{{=value.id}}" data-num="{{=value.readcount}}">
        <div class="jobname">
            <span>{{=value.jobname}}</span>
            <span style="color:#FEA82F">{{=value.salary}}</span>
        </div>
        <div class="jobcompany" style="color:#989898">
            <div>
                <img src="../image/icon/company.png" alt="">
                <span>{{=value.company}}</span>
            </div>
            <span>{{=value.address}}</span>
        </div>
        <div class="jobaddress" style="color:#989898">
            <div class="length">
                {{? value.paytype}}
                <span>{{=value.paytype}}</span> {{??}}
                <i></i> {{?}} {{? value.cyclelength}}
                <span>{{=value.cyclelength}}</span> {{??}}
                <i></i> {{?}} {{? value.type}}
                <span>{{=value.type}}</span> {{??}}
                <i></i> {{?}} {{? value.description}}
                <span>{{=value.description}}</span> {{??}}
                <i></i> {{?}}
            </div>
            <div class="readcount">
                <img src="../image/icon/hot.png" alt="">
                <span id="number">{{=value.readcount}}</span>
            </div>
        </div>
    </li>
    {{~}}
</script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.3.min.js"></script>
<script src="../script/doT.min.js" charset="utf-8"></script>
<script type="text/javascript">
    apiready = function() {

    };

    $('.search').bind('input propertychange', function() {
        var searchVal = $(this).val();
        if (searchVal != '' && $.trim(searchVal).length != 0) {
            $('.searchbox').css('display', 'none');
        } else {
            $('.searchbox').show();
            $('.infolist-content li').css('display', 'none');
        }
    })

    $('#Clerk').click(function() {
        api.ajax({
            url: 'http://122.112.138.133/wangt/jianzhi/searchJob.com',
            method: 'post',
            data: {
                body: {
                    "data": {
                        jobname: $(this).text()
                    }
                }
            }
        }, function(ret, err) {
            if (ret) {
                if (ret.data.total > 0) {
                    $('.searchbox').css('display', 'none');
                    $('.infolist-content').append(parttime_render('job', ret.data.records));
                    $('.infolist-content li').click(function() {
                        var num = Number($(this).attr('data-num')) + 1;
                        $(this).find('#number').text(num);
                        $(this).attr('data-num', num);
                        var id = $(this).attr('data-id');
                        api.ajax({
                            url: 'http://122.112.138.133/wangt/jianzhi/updateReadCount.com',
                            method: 'post',
                            data: {
                                body: {
                                    'tbname': 'jobinfo',
                                    'id': id,
                                    'readcount': num
                                }
                            }
                        }, function(ret, err) {
                            if (ret) {}
                        });
                        api.openWin({
                            name: 'jobdetails',
                            url: './jobdetails.html',
                            pageParam: {
                                id: $(this).attr('data-id')
                            }
                        });
                    })
                } else {
                    api.toast({
                        msg: '没有搜到任何内容呢',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }
        });
    })

    $('#Leaflets').click(function() {
        api.ajax({
            url: 'http://122.112.138.133/wangt/jianzhi/searchJob.com',
            method: 'post',
            data: {
                body: {
                    "data": {
                        jobname: $(this).text()
                    }
                }
            }
        }, function(ret, err) {
            if (ret) {
                if (ret.data.total > 0) {
                    $('.searchbox').css('display', 'none');
                    $('.infolist-content').append(parttime_render('job', ret.data.records));
                    $('.infolist-content li').click(function() {
                        var num = Number($(this).attr('data-num')) + 1;
                        $(this).find('#number').text(num);
                        $(this).attr('data-num', num);
                        var id = $(this).attr('data-id');
                        api.ajax({
                            url: 'http://122.112.138.133/wangt/jianzhi/updateReadCount.com',
                            method: 'post',
                            data: {
                                body: {
                                    'tbname': 'jobinfo',
                                    'id': id,
                                    'readcount': num
                                }
                            }
                        }, function(ret, err) {
                            if (ret) {}
                        });
                        api.openWin({
                            name: 'jobdetails',
                            url: './jobdetails.html',
                            pageParam: {
                                id: $(this).attr('data-id')
                            }
                        });
                    })
                } else {
                    api.toast({
                        msg: '没有搜到任何内容呢',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }
        });
    })

    $('.searchBtn').click(function() {
        var searchVal = $('.search').val();
        if (searchVal == '' || $.trim(searchVal).length == 0) {
            api.toast({
                msg: '请输入搜索内容再搜索',
                duration: 2000,
                location: 'bottom'
            });
            return
        }
        api.ajax({
            url: 'http://122.112.138.133/wangt/jianzhi/searchJob.com',
            method: 'post',
            data: {
                body: {
                    "data": {
                        jobname: searchVal
                    }
                }
            }
        }, function(ret, err) {
            if (ret) {
                if (ret.data.total > 0) {
                    $('.searchbox').css('display', 'none');
                    $('.infolist-content').append(parttime_render('job', ret.data.records));
                    $('.infolist-content li').click(function() {
                        var num = Number($(this).attr('data-num')) + 1;
                        $(this).find('#number').text(num);
                        $(this).attr('data-num', num);
                        var id = $(this).attr('data-id');
                        api.ajax({
                            url: 'http://122.112.138.133/wangt/jianzhi/updateReadCount.com',
                            method: 'post',
                            data: {
                                body: {
                                    'tbname': 'jobinfo',
                                    'id': id,
                                    'readcount': num
                                }
                            }
                        }, function(ret, err) {
                            if (ret) {}
                        });
                        api.openWin({
                            name: 'jobdetails',
                            url: './jobdetails.html',
                            pageParam: {
                                id: $(this).attr('data-id')
                            }
                        })
                    })
                } else {
                    api.toast({
                        msg: '没有搜到任何内容呢',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }
        });

    })

    function parttime_render(id, elements, options) {
        var options = options || {};
        var elementObj = doT.template($api.byId(id).innerHTML);
        var elementData = $.extend({
            items: elements
        }, options);
        return elementObj(elementData);
    }
</script>

</html>
